﻿using System;
using System.Collections.Generic;
using System.Linq;
using GTAuto.DAL.Entities;
using GTAuto.DAL.Enums;
using GTAuto.DAL.Extensions;

namespace GTAuto.DAL.DAL
{
    public class DALPropertyCategory : DALBase
    {
        public static DALPropertyCategory Singleton = new DALPropertyCategory();
        

        public List<GTPropertyCategory> GetAll()
        {
            using (var db = new GTAutoDataClassesDataContext(ConnectionString))
            {
                var cats = db.PropertyCategories.ToList();
                
                var ret = new List<GTPropertyCategory>();
                
                foreach (var item in cats)
                {
                    var gtBrand = new GTPropertyCategory();
                    gtBrand.UpdateTo(item);
                    ret.Add(gtBrand);
                }
                
                return ret;
            }
        }

        public List<GTPropertyCategory> GetAll(BrandTypeEnum brandTypeEnum)
        {
            using (var db = new GTAutoDataClassesDataContext(ConnectionString))
            {
                var cats = db.PropertyCategories.Where(x => x.Type == (decimal) brandTypeEnum).ToList();

                var ret = new List<GTPropertyCategory>();

                foreach (var item in cats)
                {
                    var gtBrand = new GTPropertyCategory();
                    gtBrand.UpdateTo(item);
                    ret.Add(gtBrand);
                }

                return ret;
            }
        }


        public GTPropertyCategory Get(int id)
        {
            using (var db = new GTAutoDataClassesDataContext(ConnectionString))
            {
                var cats = db.PropertyCategories.SingleOrDefault(x => x.Id == id);
                
                    var gtBrand = new GTPropertyCategory();
                    gtBrand.UpdateTo(cats);

                return gtBrand;
            }
        }


    }
}
